from flask import Flask, redirect, url_for
from flask_cors import *
import json

app = Flask(__name__)
# 允许跨域请求
CORS(app, support_credentials=True)


@app.route('/admin')
def hello_admin():
    return "hello_admin"


@app.route('/guest/<guest>')
def hello_guest(guest):
    return 'hello %s' % guest


@app.route('/zyd')
def say_hello():
    lis = ['zyd', 'python', 'java']
    return json.dumps(lis)


@app.route('/user/<name>')
def hello_user(name):
    if name == 'admin':
        return redirect(url_for('hello_admin'))
    else:
        return redirect(url_for('hello_guest', guest=name))


if __name__ == '__main__':
    app.run(debug=True, host='127.0.0.1', port=5000)
